/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package beans;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;

/**
 *
 * @author Nina
 */
@ManagedBean
@SessionScoped
public class ManagedBeanLogin {

    private String userName;
    private String userPassword;

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getUserPassword() {
        return userPassword;
    }

    public void setUserPassword(String userPassword) {
        this.userPassword = userPassword;
    }

    public String login() {
        userName = "";
        userPassword = "";
        FacesContext fcon = FacesContext.getCurrentInstance();
        HttpServletRequest request = (HttpServletRequest) fcon.getExternalContext().getRequest();
        if (!request.isUserInRole("admin")) {
            return "/faces/index.xhtml";
        } else {
            return "/faces/indexAdmin.xhtml";
        }
    }

    public ManagedBeanLogin() {
        
    }
}
